<template>
	<view>
		<view class="top_bg"></view>
		<view class="contents">
			<!-- <view class="" style="display: flex;">
				<view class="" style="width: 40%;">
					到账账户:
				</view>
				<view class="" style="width: 60%;">
					XXX
				</view>
			</view> -->
			<view class="xian"></view>
			<view class="" style="display: flex;">
				<view class="" style="width: 40%;">
					到账方式:
				</view>
				<view class="" style="width: 60%;color: green;">
					微信零钱
				</view>
			</view>
			<view class="xian"></view>
			<view class="" style="display: flex;">
				<view class="" style="width: 40%;">
					提现金额:
				</view>
				<view class="" style="width: 60%;color: #1262DB;">
					<input type="digit" v-model="money" @input="numberFixedDigit"/>
				</view>
			</view>
			<view class="xian"></view>
			<view class="" style="font-size: 20rpx;color:#848484">
				可提现收益金额￥{{ketixian}}
			</view>
			<view class="tx" @click="tixians()">
				提现
			</view>
			<view style="margin-top: 30rpx;font-size: 30rpx;text-align: right;" @click="tixianjilu">提现记录</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money:0,
				ketixian:0,
				types:1
			}
		},
		onLoad(option) {
			if(option.types){
				this.types = option.types
			}
			// 获取用户信息，包括余额
			this.getdata()
		},
		methods: {
			tixianjilu(){
				console.log('提现记录')
				uni.navigateTo({
					url:'/pages/clinic/txjl'
				})
			},
			numberFixedDigit (e) { // 固定两位小数
				var that = this;
				console.log(e);
				e.target.value = (e.target.value.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
				this.$nextTick(() => {
					that.money = e.target.value
					// if(that.money > that.ketixian){
					// 	that.money = that.ketixian
					// }
				})
			},
			tixians	(){
				var that = this
				if(that.money == 0){
					uni.showToast({
						title: "提现金额不足",
						icon: 'error'
					})
					return;
				}
				uni.request({
				    url: that.global.url + 'api/clinic/tixian_money',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						'id': uni.getStorageSync('clinic_id'),
						'money': that.money,
						'types':that.types
					},
				    success(res) {
						console.log(res);
				        let result = res.data
						console.log(result);
						
				        if(result.code == 1){
							uni.showToast({
								title: result.msg,
								icon: 'success'
							})
							that.getdata()
						}else{
							uni.showToast({
								title: result.msg,
								icon: 'error'
							}) 
				        }
				    }
				})
			},
			getdata(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/clinic/clinic_money',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						'id': uni.getStorageSync('clinic_id'),
						'types':that.types
					},
				    success(res) {
						console.log(res);
				        let result = res.data
						console.log(result);
						
				        if(result.code == 1){
							that.money = result.data
							that.ketixian = result.data
						}else{
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
				        }
				    }
				})
			}
		}
	}
</script>

<style>
.top_bg{
	position: absolute;
	background-color: #1262DB;
	height: 160rpx;
	width: 100%;
}
.contents{
	position: relative;
	height: 400rpx;
	width: 80%;
	margin: 0px auto;
	z-index: 999;
	background-color: #fff;
	border-radius: 20rpx;
	top: 40rpx;
	display: flex;
	flex-direction: column;
	padding: 30rpx;
}
.xian{
	border-bottom: 1px solid #e8e8e8;
	margin-top: 15rpx;
	margin-bottom: 15rpx;
}
.tx{
	width: 100%;
	background-color: #1262DB;
	text-align: center;
	font-size: 32rpx;
	padding: 15rpx 0rpx;
	margin: 0px auto;
	margin-top: 70rpx;
	color: #fff;
	border-radius: 15rpx;
}
page{
	background-color: #eaeaea;
}
</style>
